import time
from public.settins import Pandas_to_Dict, Start_Thread, Openpyxl_to_Excel, EXCEL_FILE, Save_to_Txt
from apps.pssh import run
from tqdm import tqdm

def menu() -> int:
    p = """
1.保存到excel
2.保存到txt
:::默认保存到excel:::
:::如果输出的内容里面是空白的请查看public下的log文件:::
    """
    print(p)
    try:
        i = int(input("请选择："))
        return i
    except ValueError as v:
        return 1
    except Exception as e:
        return 1


def main():
    o = menu()
    try:
        device_list = Pandas_to_Dict(EXCEL_FILE, "host")
        data_list = Start_Thread(run, device_list)
        if o == 1 or o not in [1, 2]:
            for obj in tqdm(data_list):
                Openpyxl_to_Excel(obj)
        else:
            for obj in tqdm(data_list):
                Save_to_Txt(obj)

    except FileNotFoundError as f:
        print("excel文件不存在！")
    except Exception as e:
        print(e)


if __name__ == '__main__':
    main()
